<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>

<script>
  //开启只执行一次的定时器
  setTimeout(function (){
    console.log("时间到");

  },3000);
  let count = 0;
  //开启每秒执行一次的定时器
  let h1 = document.querySelector("h1");
  let timer = setInterval(f,1000);
  //setInterval(f,1000);
  function f() {
    count++;
    h1.innerText = count;
    //停止定时器
    if (count == 5){
      clearInterval(timer);
    }
  }
</script>

</body>
</html>